package com.hh.workflow.action;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.hh.baseframework.exception.MessageException;
import com.hh.system.util.base.BaseAction;
import com.hh.system.util.model.ReturnModel;
import com.hh.workflow.bean.HhWorkFlowInfo;
import com.hh.workflow.service.impl.WorkFlowInfoService;
import com.opensymphony.xwork2.ModelDriven;

@SuppressWarnings("serial")
public class ActionWorkFlowInfo extends BaseAction implements
		ModelDriven<HhWorkFlowInfo> {
	private HhWorkFlowInfo workFlowInfo = new HhWorkFlowInfo();
	private String imgxml;
	@Autowired
	private WorkFlowInfoService workFlowInfoService;

	public HhWorkFlowInfo getModel() {
		return workFlowInfo;
	}

	public void save() {
		try {
			HhWorkFlowInfo workFlowInfo2 = workFlowInfoService.save(
					this.workFlowInfo, imgxml);
			this.getResultMap().put("object", workFlowInfo2);
		} catch (MessageException e) {
			this.getResultMap().put("returnModel",
					new ReturnModel(e.getMessage()));
		}
		this.returnResult();
	}

	public void findObjectByDataId() {
		HhWorkFlowInfo hhXtForm = workFlowInfoService
				.findObjectByDataId(this.workFlowInfo.getDataId());
		if (hhXtForm != null) {
			hhXtForm.setMxgraphXml(hhXtForm.getMxgraphXml()
					.replaceAll("!gt;", "&gt;").replaceAll("!lt;", "&lt;")
					.replaceAll("!quot;", "&quot;")
					.replaceAll("!amp;", "&amp;"));
		}

		this.returnResult(hhXtForm);
	}

	public void deleteByIds() {
		workFlowInfoService.deleteByIds(this.getIds());
	}

	public String getImgxml() {
		return imgxml;
	}

	public void setImgxml(String imgxml) {
		this.imgxml = imgxml;
	}

}
